package com.hhkj.admin.question.controller;

import com.hhkj.admin.question.domain.Question;
import com.hhkj.admin.question.model.extend.QuestionImportModel;
import com.hhkj.admin.question.model.req.ExcelTypeCountReq;
import com.hhkj.admin.question.model.req.QuestionReq;
import com.hhkj.admin.question.model.res.QuestionRes;
import com.hhkj.admin.question.service.biz.QuestionBizService;
import com.ruoyi.common.annotation.LogTitlePrefix;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.excl.utils.ExcelUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 题目信息Controller
 *
 * @author ruoyi
 * @since 2023-05-16
 */
@LogTitlePrefix("题库信息")
@PermissionPrefix("train:question")
@RestController
@RequestMapping("/question")
public class QuestionController extends BaseController<Question, QuestionReq, QuestionRes, QuestionBizService>
{

    /** 题库题目导入模板下载 */
    @GetMapping("/import/template/download")
    public void downloadQuestionImportTemplate(HttpServletResponse response)
    {
        ExcelUtils.downLoadExcel(QuestionImportModel.FILE_NAME, response, this.getBizService().createImportTemplate());
    }

    /** 根据类型统计excel中的题目数量 */
    @PreAuthorize("@ss.hasPermi(this, '')")
    @PostMapping("/import/excel/analysis")
    public AjaxResult analysisImportExcel(@RequestBody ExcelTypeCountReq req)
    {
        return AjaxResult.success(this.getBizService().analysisImportExcel(req));
    }
}
